In computer programming, a trait is a collection of methods, used as a "simple conceptual model for structuring object oriented programs".[1] [2] [3] Traits are similar to mixins, but whereas mixins can be composed only using the inheritance operation, traits offer a much wider selection of operations, including symmetric sum, method exclusion, and aliasing. A Trait differs from an abstract type in that it provides implementations of its methods, not just type signatures.
Traits come from the Self programming language and are supported as a native language feature in the Fortress programming language (where they also play the role of types), in the Scala programming language,[4][5] the Pharo version of Squeak Smalltalk, as "categories" in the Objective-C language, and in Perl 6 (which calls them "roles"), as an add-on by the Moose module for Perl 5 and the Joose framework for JavaScript and will be included in PHP 5.4[6]. Abstract classes as mixins in the multiple-inheritance Curl programming language permit method implementations and thus constituted traits by another name. Module mixins in Ruby are similar to traits to some degree. Racket supports traits as a library and uses macros, structures, and first-class classes to implement them.
Traits for the Smalltalk programming language were initially developed at the Software Composition Group, University of Bern.[7]